import tushare as ts
import pandas as pd
import talib

# 导入tushare
import tushare as ts

# 初始化pro接口
pro = ts.pro_api('3ea113a837100c59e12d05f30550659081f71e58f11b6b0d7b1a0006')

# 拉取数据
df = pro.daily(**{
    "ts_code": "",
    "trade_date": "",
    "start_date": 20250401,
    "end_date": 20250411,
    "offset": "",
    "limit": ""
}, fields=[
    "ts_code",
    "trade_date",
    "open",
    "high",
    "low",
    "close",
    "pre_close",
    "change",
    "pct_chg",
    "vol",
    "amount"
])
# 数据统计表
statistics = df.describe()
print("数据统计表:")
print(statistics)
# 对数据进行排序
df = df.sort_values(by=['ts_code', 'trade_date'])
# 分股票计算技术指标
df['ma5'] = df.groupby('ts_code')['close'].transform(lambda x: talib.SMA(x, timeperiod=5))
df['ma10'] = df.groupby('ts_code')['close'].transform(lambda x: talib.SMA(x, timeperiod=10))
df['rsi'] = df.groupby('ts_code')['close'].transform(lambda x: talib.RSI(x, timeperiod=14))
print(df)
# 提取买点股票
last_data = df.groupby('ts_code').last()
buy_stocks = last_data[last_data['ma5'] > last_data['ma10']]
print("买点股票列表:")
print(buy_stocks.index.tolist())

